<!DOCTYPE html>

<html>
    <head>
        <meta charset="UTF-8">
        <title>动态插槽名称</title>
        <style type="text/css">
            .base-layout {
                border: 1px solid blue;
            }
            .base-layout>* {
                margin: 15px ;
                border: 1px solid salmon ;
            }
            .slot-content{
                color: #ff0;
                background: #4b4bff;
            }
        </style>
    </head>
    <body>
        
        <div id="root">
            <input type="radio" v-model="slotname" value="header" id="header">
            <label for="header" >header</label>
            <input type="radio" v-model="slotname" value="middle" id="middle">
            <label for="middle" >middle</label>
            <input type="radio" v-model="slotname" value="footer" id="footer">
            <label for="footer" >footer</label>
            <base-layout>
                <template v-slot:[slotname]>
                    <div class="slot-content">
                        由父组件分发的内容
                    </div>
                </template>
            </base-layout>
        </div>

        <!-- 导入 vue.js 3.x 核心库 -->
        <script src="../scripts/vue@3.2.31.js"></script>

        <script>
            const BaseLayout = {
                template: `<div class="base-layout">
                                <slot name="header">
                                    <div>Header</div>
                                </slot>
                                <slot name="middle">
                                    <div>middle</div>
                                </slot>
                                <slot name="footer">
                                    <div>footer</div>
                                </slot>
                                <button @click="handler">访问插槽</button>
                           </div>`,
                methods: {
                    handler(){
                        console.log( this );
                        console.log( this.$slots );
                    }
                }
            }
            const options = {
                data(){
                    return {
                        slotname: 'middle'
                    }
                }
            }
            const app = Vue.createApp(options);
            app.component( 'base-layout' , BaseLayout );
            const root = app.mount('#root');
            console.log( root );
        </script>
    </body>
</html>